package week1;

/**
 * Created by YanChenDeng on 2016/10/13.
 */
public class QuickFind extends UF {
    public QuickFind(int n) {
        super(n);
    }

    @Override
    public void union(int p, int q) {
        for (int i = 0; i < id.length; i++){
            if (id[i] == id[p])
                id[i] = id[q];
        }
    }

    @Override
    public boolean connected(int p, int q) {
        return id[p] == id[q];
    }

    @Override
    public int find(int p) {
        return id[p];
    }
}
